package com.qfedu.scode.filter;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @program: Boot2008
 * @description:
 * @author: Feri(邢朋辉)
 * @create: 2021-01-04 10:23
 */
@Component
@WebFilter("/*")
public class CrosFilter implements Filter {
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        //设置跨域的各种参数
        HttpServletResponse response=(HttpServletResponse)servletResponse;
        //设置参数
        response.addHeader("Access-Control-Allow-Origin","*");

        response.addHeader("Access-Control-Allow-Methods","GET,POST,PUT,DELETE");
        response.addHeader("Access-Control-Max-Age","3600");
        response.addHeader("Access-Control-Allow-Headers","content-type,sctoken");
        response.addHeader("Access-Control-Allow-Credentials","true");
        filterChain.doFilter(servletRequest, response);
    }
}
